<!-- 通过 IP 地址查找主机所在地 -->
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
        IP地址：<input type="text" name="ipaddr">
        <br>
        对应数字：<input type="text" name="ipNum">
        <button onclick="deal()">转换</button>
    <script>
        function deal(myform) {
            var ip = form1.ipaddr.value;
            objExp = /(\d+).(\d+).(\d+).(\d+)/;
            if (ip == "") {
                alert("请输入IP地址");form1.ip.focus();return;
            }
            if (objExp.test(ip)) {
                myform.ipNum.value = convert(ip);
            } else {
                alert("您输入的 IP 地址不合法！");form1.ip.focus();return;
            }
        }

        function convert() {
            ip = ipaddr.split(".");
            vip = ip[0]*255*255*255+ip[1]*255*255+ip[2]*255+ip[3]*1;
            return vip;
        }
    </script>
</body>
</html>